import { fork, put, take } from "redux-saga/effects";
import { BreezeAction } from "../interface/state";
import { ServiceActionType } from "../utils/constant";
import { mutationActionType } from "../utils/mutation";

export function* mutate(action: BreezeAction) {
  const mutation = {
    ...action,
    type: mutationActionType(action)
  };
  yield put(mutation);
}
export function* watchMutation() {
  while (true) {
    const action: BreezeAction = yield take(ServiceActionType.StoreMutation);
    yield fork(mutate, action);
  }
}